package com.example.administrator.yuejian_2.fragment;


<<<<<<< HEAD
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
=======
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.RadioGroup;
import android.widget.ViewFlipper;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.TrainSearchActivity;
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2

/**
 * A simple {@link Fragment} subclass.
 */
public class TrainFragment extends Fragment {
<<<<<<< HEAD


=======
    private RadioGroup trainbutton;
    private TrainPrimerFragment trainPrimerFragment;
    private TrainNoobFragment trainNoobFragment;
    private TrainAdvanceFragment trainAdvanceFragment;
    private TrainAllFragment trainAllFragment;
    private ImageButton train_search;

    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;

    ViewFlipper viewFlipper;
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
    public TrainFragment() {
        // Required empty public constructor
    }

<<<<<<< HEAD

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_train, container, false);
    }

}
=======
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        //在Fragment中添加Fragment时，调用getChildFragmentManager获取FragmentManager
        fragmentManager = getChildFragmentManager();
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_train, container, false);

    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        train_search = view.findViewById(R.id.train_search);
        train_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), TrainSearchActivity.class);
                startActivity(intent);
            }
        });
        viewFlipper= view.findViewById(R.id.flipper);
        viewFlipper.startFlipping();

        trainbutton = view.findViewById(R.id.train_button);
        trainbutton.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.train_primer:
                        trainPrimerFragment = new TrainPrimerFragment();
                        replaceFragment(trainPrimerFragment);
                        break;
                    case R.id.train_noob:
                        trainNoobFragment = new TrainNoobFragment();
                        replaceFragment(trainNoobFragment);
                        break;
                    case R.id.train_advance:
                        trainAdvanceFragment = new TrainAdvanceFragment();
                        replaceFragment(trainAdvanceFragment);
                        break;
                    case R.id.train_all:
                        trainAllFragment=new TrainAllFragment();
                        replaceFragment(trainAllFragment);
                        break;

                }
            }
        });
        trainbutton.check(R.id.train_primer);
    }

    private void replaceFragment(Fragment fragment){

        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_holder_train,fragment);
        fragmentTransaction.commit();

    }

}
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
